package com.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.entity.ProductEntity;
import com.service.ProductService;
import com.utils.R;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Losca
 * @date 2022/4/29 19:16
 */
@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;
    @GetMapping("/allProduct")
    public R  allProduct(@RequestParam(defaultValue = "1") Integer pageNum
            , @RequestParam(defaultValue = "10") Integer pageSize
            , @RequestParam(defaultValue = "") String value) {
        Page<ProductEntity> productEntityPage = productService.allProduct(pageNum, pageSize, value);
        return R.ok().put("data", productEntityPage);
    }
    @PostMapping("/updateProduct")
    public R updateProduct(ProductEntity product,String[] machines){
        String join = StringUtils.join(machines, ",");
        product.setMachine(join);
        productService.updateById(product);
        return R.ok();
    }
    @GetMapping("/delProduct")
    public R delProduct(Integer id){
        productService.deleteById(id);
        return R.ok();
    }
}
